<?php
!defined('IN_ROOT') && exit( 'Access Denied' );
class LogisticController extends AdminModuleController {	

	function _category($model=0) {
		$categorys = $this->CategoryModel->findAll("`storeId`=1 AND parentId='0'");
		$r = array();
		foreach($categorys as $v) {
			$r[] = $v;			
			$arr = $this->CategoryModel->findAll("parentId='{$v['categoryId']}'");
			foreach($arr as &$v2) {
				$v2['cateName'] = "&nbsp;&nbsp;&nbsp;&nbsp;--".$v2['cateName'];
			}
			$r = array_merge($r, $arr);
		}
		return $r;
	}
	
	public function actionAdmin() {
		$page = max(1, getgpc('page'));
		
		$sqladd = "";
		$logisticList = $this->LogisticModel->findAll($sqladd, $page, GODHOUSE_PPP3);
		$num = $this->LogisticModel->count($sqladd);
		$multipage = page($num, GODHOUSE_PPP3, $page, 'logistic-admin.htm');
		
		$this->view->assign('multipage', $multipage);
		$this->view->assign('logisticList', $logisticList);
		$this->display('logistic_admin');
	}
	
	public function actionCreate() {
		if($logistic = getgpc('logistic', 'P')) {
			
			$this->LogisticModel->insert($logistic);
			$this->alert('添加成功。', 'logistic-admin.htm');
		}
		
		$this->view->assign('categorys', $this->CategorysPublic->get_options(GODHOUSE_CATEGORY_GIFTS));
		$this->view->assign('action', 'create');
		$this->display('logistic_create');
	}
	
	public function actionUpdate() {
		$logisticId = getgpc(2);
		$model = $this->LogisticModel->findByPk($logisticId);
		
		if($logistic = getgpc('logistic', 'P')) {
			$this->LogisticModel->updateByPk($logisticId, $logistic);
			$this->alert('修改成功。', 'logistic-admin.htm');
		}
		
		
		
		$this->view->assign('logistic', $model);
		$this->view->assign('logisticId', $logisticId);
		$this->view->assign('action','update');
		$this->display('logistic_create');
	}
	
	public function actionDelete() {
		$logisticId = getgpc(2);
		$model = $this->LogisticModel->findByPk($logisticId);
		$this->LogisticModel->deleteByPk($logisticId);
		$this->message('删除成功。');
	}
}